package com.java.example.network

import com.blankj.utilcode.util.DeviceUtils
import com.java.example.network.api.HttpAPI
import com.java.example.network.response.BaseResponse
import com.java.example.network.response.LoginResponse
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.util.concurrent.TimeUnit

/**
 * Date：2021/1/8 12:52 PM
 * Creator：chenll
 */
class RequestUtil {
    lateinit var mApiService: HttpAPI
    fun login(username: String, password: String): Observable<BaseResponse<LoginResponse>> {
        return mApiService.login(username, password, DeviceUtils.getMacAddress()).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .timeout(1000 * 20, TimeUnit.MILLISECONDS)
    }

    companion object {
        val instance: RequestUtil by lazy {
            val requestUtil = RequestUtil()
            val retrofit = RetrofitUtil.sRetrofit
            requestUtil.mApiService = retrofit.create(HttpAPI::class.java)
            requestUtil
        }
    }
}
